<template>
	<view class="p-10">
		<view class="card">
			<my-forms ref="valiForm" :model="valiFormData" :label-position="'top'" :formItem="formData"></my-forms>
			<u-button type="primary" shape="circle" text="确定" @click="submit"></u-button>
		</view>
	</view>
</template>
<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		reactive,
		ref,
	} from 'vue'
	import {
		HiddenDangerNotice
	} from '@/api/hidden-danger.js'
	// 表单数据
	let formData = reactive([{
		itemType: 'select',
		type: 'GETuseList',
		label: '受理人',
		required: true,
		prop: 'users',
		multiple: true
	}, {
		label: '申请原因',
		type: 'textarea',
		required: true,
		prop: 'applyInfo'
	}])
	const valiForm = ref(null)
	const valiFormData = reactive({
		ids: []
	})
	// 保存提交
	const submit = () => {
		valiForm.value.$refs.refMyForm.validate().then(async (res) => {
			const {
				code,
				msg
			} = await HiddenDangerNotice(valiFormData)
			if (code == 200) {
				uni.showToast({
					icon: 'success',
					title: `下达成功`
				})
				uni.navigateBack({
					delta: 2 // 返回的页面数，如果是1则返回上一页
				})
			} else {
				uni.showToast({
					title: msg
				})
			}
		}).catch(err => {
			console.log('err', err);
			uni.showToast({
				icon: 'error',
				title: err[0].errorMessage
			})
		})
	}

	onLoad((e) => {
		valiFormData.ids.push(e.id)
	})
</script>
<style lang="scss" scoped>
</style>